package guda.stark.biz.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import guda.stark.biz.ElecRuleBiz;
import guda.stark.dal.dao.ElecRuleDAO;
import guda.stark.dal.dataobject.ElecRuleDO;
import guda.grape.autogen.common.page.BaseQuery;
import guda.grape.autogen.common.page.BizResult;

public class ElecRuleBizImpl implements ElecRuleBiz{

    private final static Logger logger = LoggerFactory.getLogger(ElecRuleBizImpl.class);

    @Autowired
    private ElecRuleDAO elecRuleDAO;

    public BizResult detail(long id) {
        BizResult bizResult = new BizResult();
        try{
            ElecRuleDO elecRuleDO = elecRuleDAO.getElecRuleById(id);
            bizResult.data.put("elecRuleDO", elecRuleDO);
            bizResult.success = true;
        }catch(Exception e){
            logger.error("query ElecRule error",e);
        }
        return bizResult;
}

    public BizResult list(BaseQuery baseQuery) {
        BizResult bizResult = new BizResult();
        try {
            int totalCount = elecRuleDAO.countForPage(baseQuery);
            baseQuery.setTotalCount(totalCount);
            List<ElecRuleDO> elecRuleList = elecRuleDAO.selectForPage(baseQuery);
            bizResult.data.put("elecRuleList", elecRuleList);
            bizResult.data.put("query", baseQuery);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("view ElecRule list error", e);
        }
            return bizResult;
     }

    public BizResult delete(long id) {
        BizResult bizResult = new BizResult();
        try {
            elecRuleDAO.delElecRuleById(id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("delete elecRule error", e);
        }
        return bizResult;
    }

    public BizResult create(ElecRuleDO elecRuleDO) {
        BizResult bizResult = new BizResult();
        try {
            long id = elecRuleDAO.insert(elecRuleDO);
            bizResult.data.put("id", id);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("create ElecRule error", e);
        }
        return bizResult;
    }

    @Override
    public BizResult update(ElecRuleDO elecRuleDO) {
        BizResult bizResult = new BizResult();
        try {
            elecRuleDAO.updateByIdSelective(elecRuleDO);
            bizResult.success = true;
        } catch (Exception e) {
            logger.error("update ElecRule error", e);
        }
        return bizResult;
    }


}
